﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DoNet.FrameWork.Services.Impl;
using DoNet.FrameWork.Repository;
using DoNet.FrameWork.Repository.Specification;

using Authority.Entity;
using Authority.Repositories;

namespace Authority.Services.Impl
{
    public class PostServiceImpl: ServicesBase<Post>, IPostService
    {
        public PostServiceImpl(IUnitOfWork _context, IPostRepository _Repository)
            : base(_context, _Repository)
        {

        }

        public string InsertOrEditPost(Post entity)
        {
            ISpecification<Post> condition = new DirectSpecification<Post>(p => p.Id == entity.Id);
            Post post = base.GetByCondition(condition);
            if (post != null)
            {
                post.Code = entity.Code;
                post.OrganizeId = entity.OrganizeId;
                post.PostName = entity.PostName;
                //post.SysCreatedBy = entity.SysCreatedBy;
                //post.SysCreatedOn = entity.SysCreatedOn;
                post.SysModifiedBy = entity.SysModifiedBy;
                post.SysModifiedOn = entity.SysModifiedOn;
                base.Modify(post);
            }
            else
            {
                base.NewSave(entity);
            }
            return "保存成功！";
        }

        public string DeletePostById(Guid id)
        {
            ISpecification<Post> condition = new DirectSpecification<Post>(o => o.Id == id);
            //Post post = base.GetByCondition(condition);
            base.Remove(condition);
            return "删除成功！";
        }
    }
}
